<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php include('menu.php'); ?>
<script>
function focus(){
	document.formedit.name.focus();
}
</script>
</head>
<body onload="focus();">
<?php

//แก้ไข
if($_GET["action"]=="update") {

	if($_POST['name'] != "")
		{
			$Query = "UPDATE unit SET unit_name = '".$_POST["name"]."' WHERE unit_id = '".$_POST["category_id"]."' ";
			$objQuery = mysql_query($Query);
			
			header('Location: unit_manage.php');
		}
}

$Query = "SELECT unit_name FROM unit WHERE unit_id = '".$_GET["id"]."'";
$objQuery = mysql_query($Query) or die ("Error Query [".$Query."]");
$row = mysql_fetch_array($objQuery);
?>
<form action="?action=update" name="formedit" method="post" id="formedit">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>แก้ไขหน่วยนับ</h1>
    <div class="buttons"><a onclick="document.formedit.submit();" class="button"><span>บันทึก</span></a><a onclick="location = 'unit_manage.php';" class="button"><span>ยกเลิก</span></a></div></div>
  <div class="content">
    <table class="form">
      <tr>
        <td>ชื่อหน่วยนับ : </td>
        <td><input name="name" type="text" id="name" value="<?php echo $row["unit_name"];?>" /><input type="hidden" name="category_id" value="<?php echo $_GET['id']; ?>" /></td>
      </tr>
    </table>
  </div>
</div>
</form>
</body>
</html>
